﻿using CommonDevelop;
using CommonDevelop.DB;
using ManageDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace ManageRepository
{
    public interface IPicRepository : IBase<Base_Picture>
    {
        List<string> GetPic_Address(List<long> IdLs);
        bool DeletePic(List<long> IdLs);
    }

    public class PicRepository : DBBase<Base_Picture>, IPicRepository
    {
        public override Expression<Func<Base_Picture, bool>> WhereKeyWord(string keyword)
        {
            Expression<Func<Base_Picture, bool>> expression = a => a.PicGroupNo == keyword;
            return expression;
        }

        public List<string> GetPic_Address(List<long> IdLs)
        {
            if (IdLs == null || IdLs.Count < 1)
                return new List<string>();

            var query = this.GetList(m => IdLs.Contains(m.Id)).Select(x => x.PicAddress);
            return query.ToList();
        }

        public bool DeletePic(List<long> IdLs)
        {
            if (IdLs == null || IdLs.Count < 1)
                return false;

            this.Delete_Batch(m => IdLs.Contains(m.Id));
            return true;
        }
    }
}
